public class num108 {
    public TreeNode sortedArrayToBST(int[] nums) {
        return inorderTreeNodeBuilder(nums,0,nums.length - 1);
    }

    private TreeNode inorderTreeNodeBuilder(int[] nums, int left, int right) {
        if(nums == null){
            return null;
        }
        if(left > right){
            return null;
        }
        int mid = (left + right) / 2;
        TreeNode root = new TreeNode(nums[mid]);
        root.left = inorderTreeNodeBuilder(nums,left,mid - 1);
        root.right = inorderTreeNodeBuilder(nums,mid + 1,right);
        return root;
    }
}
